package zsc.nine.onlinemall.configuration;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName: CROSFilter
 * @Description: CROSFilter of Cross-Origin
 * @Author: Zainus
 * @CreateDate: Jul.23, 2021
 * @UpdateDate: Jul.23, 2021
 * @Version: [v1.0]
 */

/**
 * @类名: CROSFilter
 * @描述: 解决跨域的过滤器
 * @创建人: 叶增钥
 * @创建时间: 2021年7月23日
 * @更新时间: 2021年7月23日
 * @版本: [v1.0]
 */
@Component
public class CROSFilter implements Filter {

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {

        HttpServletResponse response1 = (HttpServletResponse) response;
        response1.setHeader("Access-Control-Allow-Origin", "*");
        response1.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, HEAD");
        response1.setHeader("Access-Control-Max-Age", "3600");
        response1.setHeader("Access-Control-Allow-Headers", "access-control-allow-origin, authority, content-type, version-info, X-Requested-With");

        filterChain.doFilter(request, response);

    }

    public void init(FilterConfig filterConfig) {

    }

    public void destroy() {

    }

}
